<style>body {font-size:11px} pre {font:11px mono;border-bottom:1px solid #ddd; padding-bottom:0.3em; margin:0.3em;}</style>
<script src='http://protozoa.googlecode.com/svn/trunk/js/functions.js'></script>
<script src='http://protozoa.googlecode.com/svn/trunk/js/utils.js'></script>
<script src='lex3.js'></script>
<script>


var test1 = function() {
	var l = {};
	lex_merge(l, lex_rule("abc", function(){ return sprintf('[ABC:%s]', yytext) }));
	lex_merge(l, lex_rule("a", function(){ return sprintf('[A:%s]', yytext) }));
	console.dir(l);
	lex_run(l, "babca");
};

var test2 = function() {
	var l = {};
	var re = parse_re('a+');
	trace(jsonrpc_json_encode(re));
	
	var rule = lex_re(re, function(){ return sprintf('[a+:%s]', yytext) });
	trace(jsonrpc_json_encode(rule));
	console.dir(rule);
	lex_merge(l, rule);
	lex_merge(l, lex_re(parse_re('b+'), function(){ return sprintf('[b+:%s]', yytext) }));
	//lex_merge(l, lex_re(parse_re('b+'), function(){ return sprintf('[b+:%s]', yytext) }));
	
	lex_run(l, 'aaabbbb');
	
	//lex_merge(l, rule);
	//console.dir(re);
};



var test3 = function() {
	var l = {};
	var re = parse_re(/ab|cd\|/);
	var str;
	var exn;
	
	try {
		str = re_to_string(re);
	} catch(e) {
		str = 'ERROR';
		exn = e;
	};
	alert(dump(re) + '\n-----------------\n' + str);
	if (exn) throw exn;
};


var test4 = function() {
try {	
	var l = {};
	//lex_merge(l, lex_re(/pr.vet/, function(){ return sprintf('[%s]', yytext) }));
	//lex_merge(l, lex_re(/prv/, function(){ return sprintf('[%s]', yytext) }));
	
	//lex_merge(l, lex_re(/\w[\w\d]*=\d+/, function(){ return sprintf('[EQ:%s]', yytext) }));
	//lex_merge(l, lex_re(/\w[\w\d]*=\d;/, function(){ return sprintf('[EQ:%s]', yytext) }));
	
	lex_merge(l, lex_re(/(\w+)\s*=\s*(\d+)/, function(){ return sprintf('[EQ:%s=%s]', $1, $2) }));

	//trace(dump(parse_re(/a\d+/))); //return;

	//lex_merge(l, lex_re(/a(\d+)/, function(){ return sprintf('[%s]', yytext) }));
	
	
	//lex_merge(l, lex_re(/\d/, function(){ return sprintf('[%s]', yytext) }));



	//return;
	//trace(dump(l));
	
	//lex_merge(l, lex_re(/./, function(){ return sprintf('[.:%s]', yytext) }));
	lex_merge(l, lex_re(/./));
	//trace(dump(lex_re(parse_re(/./), function(){})));

	
	//lex_run(l, 'a1=1;');
	lex_run(l, 'denis=10   privet =20 a100 a23');

} catch(e) { alert('Exception: ' + e) }
};


var test5 = function() {
	var l = {};
	lex_merge(l,  lex_re(
		// /ab(d)/,
		 /((abc|ab(d))z)/, 
		// /((ab))/, 
		// /(bb*)(aa*)/,
		//  /b*(a+)/,
		function(){
			return sprintf('[%s: $0="%s"; $1="%s" $2="%s" $3="%s"]', yytext, $0, $1, $2, $3) 
		}
	));

	
	//lex_merge(l, lex_re(/(z+)(a*)/, function(){ return sprintf('[%s: $0="%s"; $1="%s" $2="%s" $3="%s"]', yytext, $0, $1, $2, $3) }));
	
	lex_merge(l, lex_re(/./, function(){ return sprintf('[.:%s]', yytext) }));

	trace(dump(l));	
	
	lex_run(l, 'abdz');
	//lex_run(l, 'bbbaaaaa');

};


//try {
	test4();
//} catch(e) {
	//throw e;
//	alert('Exception: ' + e);
//}



</script>




















